/*
 * Task 2. Arrays - neighbouring numbers 
 */
import java.util.Scanner;

/**
* Class for find two neighbouring numbers in
* an array with the smallest distance to each other.
*
*@version 1.2 21 Jan 2013
*@author Yegor Apolonov
*/
public class MinimalDistance {

    /**
     * Method inpArray creates array with size "len".
     * Elements and size of array input from keyboard
     * @return array is array of type int
     */
    private static int[] inpArray() {
               
        System.out.println("Please, enter size of array");
        /** Set the size*/
        int[] array = new int[new Scanner(System.in).nextInt()]; // Create array
        
        /** Set elements of array */
        for (int counter = 0; counter < array.length; counter++) {
           System.out.println("Please, enter element # " + counter);
           array[counter] = new Scanner(System.in).nextInt();
        }

        return array;
    }
    
    /**
     * Method sortMas find two neighbouring numbers in
     * an array with the smallest distance to each other.
     * @param arr is array of type int
     */
    private static int sortMas(int[] arr) {
        int indexOfElement = 0;
        int result;
        int min = Math.abs(arr[1] - arr[0]); //First smallest distance
               
        for (int cnt = 1; cnt < arr.length - 1; cnt++) {
             result = Math.abs(arr[cnt + 1] - arr[cnt]);
             
             if (result < min) {
                 min = result;
                 indexOfElement = cnt;
             }
        }
        return indexOfElement;
        
    }
  
   public static void main(String[] args) {
       System.out.println("\nIndex of element = " + sortMas(inpArray()));
   }

}
